package com.weishi.project.training.controller;

import com.weishi.common.utils.poi.ExcelUtil;
import com.weishi.framework.aspectj.lang.annotation.Log;
import com.weishi.framework.aspectj.lang.enums.BusinessType;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.framework.web.page.TableDataInfo;
import com.weishi.project.training.domain.ShipSpeedRecord;
import com.weishi.project.training.service.IShipSpeedRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 船速仪历史数据Controller
 */
@RestController
@RequestMapping("/training/shipSpeedRecord")
public class ShipSpeedRecordController extends BaseController {

    @Autowired
    private IShipSpeedRecordService shipSpeedRecordService;

    /**
     * 查询船速仪历史数据列表
     */
    @PreAuthorize("@ss.hasPermi('training:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShipSpeedRecord shipSpeedRecord) {
        startPage();
        List<ShipSpeedRecord> list = shipSpeedRecordService.selectShipSpeedRecordList(shipSpeedRecord);
        return getDataTable(list);
    }

    /**
     * 导出船速仪历史数据列表
     */
    @PreAuthorize("@ss.hasPermi('training:record:export')")
    @Log(title = "船速仪历史数据", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ShipSpeedRecord shipSpeedRecord) {
        List<ShipSpeedRecord> list = shipSpeedRecordService.selectShipSpeedRecordList(shipSpeedRecord);
        ExcelUtil<ShipSpeedRecord> util = new ExcelUtil<ShipSpeedRecord>(ShipSpeedRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 获取船速仪历史数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('training:record:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(shipSpeedRecordService.getById(id));
    }

    /**
     * 新增船速仪历史数据
     */
    @PostMapping
    public AjaxResult add(@RequestBody ShipSpeedRecord shipSpeedRecord) {
        shipSpeedRecordService.addShipSpeedRecord(shipSpeedRecord.getShipSpeedId(),shipSpeedRecord.getChannelId());
        return AjaxResult.success();
    }

    /**
     * 查询实时瞬时桨频数据
     */
    @GetMapping("/qryPropellerFrequencyData")
    public AjaxResult qryPropellerFrequencyData(ShipSpeedRecord shipSpeedRecord) {
        return AjaxResult.success(shipSpeedRecordService.getPropellerFrequencyData(shipSpeedRecord));
    }

    /**
     * 修改船速仪历史数据
     */
    @PreAuthorize("@ss.hasPermi('training:record:edit')")
    @Log(title = "船速仪历史数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShipSpeedRecord shipSpeedRecord) {
        shipSpeedRecordService.updateById(shipSpeedRecord);
        return AjaxResult.success();
    }

    /**
     * 删除船速仪历史数据
     */
    @PreAuthorize("@ss.hasPermi('training:record:remove')")
    @Log(title = "船速仪历史数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        shipSpeedRecordService.removeByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }
    
}